package dao;

import java.util.List;

import entity.Lieu;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;


@Stateless
@Local
public class LieuDaoJpa implements LieuDao {

	private EntityManager entityManager;
	
	@PersistenceContext(unitName="MyPersistentUnit")
	public void setEntityManager(EntityManager entityManager) {
		System.out.println("setEntityManager effectué dans LieuDaoJpa");
		this.entityManager = entityManager;
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}
	
	public LieuDaoJpa() {
		super();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Lieu> getAllLieux() {
		Query query = entityManager.createQuery("select l from Lieu as l order by l.lieu");
		List<Lieu> listeLieu = query.getResultList();
		
		return listeLieu;
	}
	
	


}
